<template>
    <view class="neme_html">
        <view class="neme_input">
            <input type="text" placeholder="请输入昵称" value="{{my_name}}" bindinput="changeVal">
            <!-- <i class="iconfont icon-guanbi"></i> -->
        </view>
        <view class="btn_box">
          <button class="button type_main" formType="submit" bindtap="commit()">提交</button>
        </view>
    </view>
</template>
<script>
    import wepy from 'wepy';
    import api from '@/api/api';
    import tip from '@/utils/tip';
    import {
        USER_INFO,USER_SPECICAL_INFO,USER_ID
    } from '@/utils/constant';

    export default class name extends wepy.page {
        config = {  // 配置当前页面
            navigationBarTitleText: '修改昵称',    // 头部标题
        }
        components = {

        }

        data = {
            my_name: ""
        }

        async modifyInfo() {
            let that = this;
            let user_id = wepy.getStorageSync(USER_ID) || '';
            api.updateUserInformation({
              query:{
                userId:user_id,
                key:'nickname',
                value:that.my_name
              },
              method:'PUT'
            },'userId='+user_id+'&key=nickname&value='+that.my_name).then(function(res){
              if(res.data.code == 0){
                wepy.navigateTo({
                  url: "/pages/personalCenter/userDetails"
                })
              }else{
                tip.error(res.data.msg)
              }
            })
        }


        onLoad(option){
            this.my_name = option.name;
        }

        methods = {  // 方法
            commit(){
                let self = this;
                self.modifyInfo();
            },
            changeVal(e){
                this.my_name = e.detail.value;
            }
        }
        events = {

        }
    }

</script>
<style lang="less">
    .neme_html{
        background: #fff;
        margin-top: 20rpx;
        border-top: 1px solid #ddd;
        .neme_input{
            padding: 0 30rpx ;
            height: 100rpx;
            line-height: 100rpx;
            display: flex;
            border-bottom: 1px solid #ddd;
            input{
                height: 100rpx;
                padding-left: 20rpx;
            }
            i{
                margin-left: auto;
            }
        }
        .btn_box{
            margin-top: 64rpx;
            margin-bottom: 64rpx;
            padding: 0 40rpx 50rpx 40rpx;
        }
    }
</style>
